var gulp = require('gulp');
var del = require('del');
var runSequence = require('run-sequence');
var connect = require('gulp-connect')
var exec = require('child_process').exec;
var $ = require('gulp-load-plugins')();

gulp.task('default', function () {
});

//清理dist
gulp.task('clean', del.bind(null, ['./task/**/*.js',"./public/javascript/all.min.js"]));

//编译iced
gulp.task('iced', function() {
  gulp.src(['./task/**/*.iced'])
    .pipe($.iced())
    .pipe($.uglify())
    .pipe(gulp.dest('./task'))
});

// 压缩合并
gulp.task('uglify', function() {
  gulp.src(['public/javascript/*js'])
    .pipe($.sourcemaps.init())
      .pipe($.concat('angular.min.js'))
      .pipe($.uglify())
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('public/javascript'));
});

// 混淆JS
gulp.task('obfuscate', function () {
  return gulp.src('public/javascript/all.min.js')
    .pipe($.obfuscate())
    .pipe(gulp.dest('public/javascript/'));
});

// runSequence任务并行
gulp.task('build', ["clean"], function(cb) {
  runSequence(
    ['default', 'iced'],
    ["uglify", 'obfuscate']
  , cb);
});

gulp.task('default', function() {
  runSequence('build');
});

console.log("Todos listening on port 8080")

